package com.gzy.gameserver;

import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Float;

public class Point2DOp 
{
	public static Point2D.Float normalize(Point2D.Float pt)
	{
		float dist = (float)pt.distance(0, 0);
		pt.x = pt.x/dist;
		pt.y = pt.y/dist;
		return pt;
	}
	
	public static float dot(Point2D.Float v1, Point2D.Float v2)
	{
		return v1.x*v2.x + v1.y*v2.y;
	}
	public static Point2D.Float add(Point2D.Float v1, Point2D.Float v2)
	{
		return new Point2D.Float(v1.x+v2.x, v1.y+v2.y);
	}
	public static Point2D.Float sub(Point2D.Float v1, Point2D.Float v2)
	{
		return new Point2D.Float(v1.x-v2.x, v1.y-v2.y);
	}
	public static Point2D.Float mut(Point2D.Float pt, float ft)
	{
		return new Point2D.Float(pt.x*ft, pt.y*ft);
	}

	public static float distanceSQ(Point2D.Float a, Point2D.Float b)
	{
		float dx = a.x - b.x;float dy = a.y - b.y;
		return dx*dx + dy*dy;
	}
	public static float distance(Point2D.Float a, Point2D.Float b)
	{
		return (float)Math.sqrt((double)distanceSQ(a, b));
	}
	public static boolean fuzzyEqual(Point2D.Float a, Point2D.Float b, float var)
	{
	    if(a.x - var <= b.x && b.x <= a.x + var)
	        if(a.y - var <= b.y && b.y <= a.y + var)
	            return true;
	    return false;
	}
}
